package com.ogawa.project6602.adapter

import android.widget.SeekBar
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ogawa.musicmodule.MUSIC_SERVER_TYPE_MIX
import com.ogawa.musicmodule.bean.JustMusicVolumeEvent
import com.ogawa.musicmodule.bean.PlayMixMusicBean
import com.ogawa.project6602.R
import com.ogawa.project6602.wdiget.JustVolumeWidget
import org.greenrobot.eventbus.EventBus

class AdjustMusicVolumeAdapter : BaseQuickAdapter<PlayMixMusicBean, BaseViewHolder>(R.layout.dialog_adjust_music_item) {
    override fun convert(helper: BaseViewHolder, item: PlayMixMusicBean?) {
        val mainJustVolumeWidget = helper.getView<JustVolumeWidget>(R.id.mainJustVolumeWidget)

        item?.let {
            mainJustVolumeWidget.setTitle(it.title)
            mainJustVolumeWidget.setProgress((it.volume*100).toInt())
        }
        mainJustVolumeWidget.setProgressListener(object : SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
                p0?.secondaryProgress= p1+3
                if (p2){//true拖动的
                    mainJustVolumeWidget.setProgress(p1)
                    EventBus.getDefault().post(JustMusicVolumeEvent().apply {
                        type = MUSIC_SERVER_TYPE_MIX
                        value = (p1/100.0f)
                        index = item!!.index
                    })
                }
            }
            override fun onStartTrackingTouch(p0: SeekBar?) {
            }
            override fun onStopTrackingTouch(p0: SeekBar?) {
            }
        })


    }

}